<?php
	namespace Api\Controller;
	use Think\Controller;
	header("Content-Type:text/html;charset=utf-8");
	class AddressController extends Controller
	{
		/* public function addressinfo()
		{
			$result = M("Areas") ->select();
			
			//var_dump($result);
			foreach ($result as $key => $value)
			{
				if ($value['id'] == $value['reid']) 
				{
					$value['city']['ciryid'] = $value['id'];
					$value['city']['cityname'] = $value['name']; 
				}
				$result[$key] = $value;
			}
			
			
			$provinceinfo = $result;
			if ($provinceinfo == null)
			{
				$array['result'] = -1;
				$array['message'] = "请求数据失败！";
				$array['addressinfo'] = $provinceinfo;
				echo json_encode($array, JSON_UNESCAPED_SLASHES);
				exit;
			}
			else
			{
				$array['result'] = 0;
				$array['message'] = "请求成功！";
				$array['provinceinfo'] = $provinceinfo;
				/* $array['cityinfo'] = $cityinfo; */
				/* $array['cityinfo'] = $cityinfo; 
				echo json_encode($array, JSON_UNESCAPED_SLASHES);
				exit;
			}
		} */
		
		public function addressinfo()
		{
			$provinceinfo = M('Areas') -> select();
			//print_r($provinceinfo);
			foreach($provinceinfo as $key=>$value)
			{
				$info = M('Areas')->where("reid={$value["id"]}") -> select();
				if($value["reid"] == 0){
					$aa["name"] = $value["name"];
					$aa["id"]=$value["id"];
					foreach ($info as $k=>$v){
						$bb[$k] =array("name" => $v["name"],
								"id" => $v["id"]);
					}
					$aa["city"] = $bb;
					/* if($value["id"] == $value["reid"]){
					 $aa = $value["name"];
					print_r($aa);
					} */
					echo "<pre>";
					//echo json_encode($aa);
					print_r($aa);
					echo "</pre>";
				}
				$provinceinfo[$key] = $aa;
		
		
			}
			json_encode($provinceinfo);
			if ($provinceinfo == null)
			{
				$array['result'] = -1;
				$array['message'] = "请求数据失败！";
				$array['addressinfo'] = $provinceinfo;
				echo json_encode($array, JSON_UNESCAPED_SLASHES);
				exit;
			}
			else
			{
				$array['result'] = 0;
				$array['message'] = "请求成功！";
				$array['provinceinfo'] = $provinceinfo;
				/* $array['cityinfo'] = $cityinfo; */
				/* $array['cityinfo'] = $cityinfo; */
				//echo json_encode($array);
				exit;
			}
		}
		
	}